<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%exhibition_hall}}".
 *
 * @property integer $id
 * @property string $title
 * @property integer $region_id
 * @property string $banner
 * @property string $litpic
 * @property string $hotpic
 * @property string $area
 * @property string $introduce
 * @property string $address
 * @property string $lat
 * @property string $lng
 * @property integer $recommend
 * @property integer $views_num
 * @property integer $order
 * @property integer $status
 * @property integer $version
 * @property string $created_by
 * @property integer $created_at
 * @property string $created_from
 * @property string $created_ip
 * @property string $updated_by
 * @property integer $updated_at
 * @property string $updated_from
 * @property string $updated_ip
 * @property integer $is_deleted
 */
class ExhibitionHall extends \common\base\BaseActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%exhibition_hall}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['region_id', 'introduce', 'lat', 'lng'], 'required'],
            [['region_id', 'recommend', 'views_num', 'order', 'status', 'version', 'created_at', 'updated_at', 'is_deleted'], 'integer'],
            [['introduce'], 'string'],
            [['title', 'banner', 'litpic', 'hotpic'], 'string', 'max' => 255],
            [['area'], 'string', 'max' => 30],
            [['address'], 'string', 'max' => 100],
            [['lat', 'lng'], 'string', 'max' => 20],
            [['created_by', 'created_from', 'created_ip', 'updated_by', 'updated_from', 'updated_ip'], 'string', 'max' => 50],
            ['views_num', 'default', 'value' => 0],
            ['order', 'default', 'value' => 0],
            ['status', 'default', 'value' => self::STATUS_FLAG_NORMAL],
            ['status', 'in', 'range' => [self::STATUS_FLAG_TEMP, self::STATUS_FLAG_NORMAL, self::STATUS_FLAG_STOP]],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'id'),
            'title' => Yii::t('common', 'title'),
            'region_id' => Yii::t('common', 'region_id'),
            'banner' => Yii::t('common', 'hall_detail_banner'),
            'litpic' => Yii::t('common', 'litpic'),
            'hotpic' => Yii::t('common', 'hotpic'),
            'area' => Yii::t('common', 'area'),
            'introduce' => Yii::t('common', 'introduce'),
            'address' => Yii::t('common', 'address'),
            'lat' => Yii::t('common', 'lat'),
            'lng' => Yii::t('common', 'lng'),
            'recommend' => Yii::t('common', 'recommend'),
            'views_num' => Yii::t('common', 'views_num'),
            'order' => Yii::t('common', 'order'),
            'status' => Yii::t('common', 'status'),
            'version' => Yii::t('common', 'version'),
            'created_by' => Yii::t('common', 'created_by'),
            'created_at' => Yii::t('common', 'created_at'),
            'created_from' => Yii::t('common', 'created_from'),
            'created_ip' => Yii::t('common', 'created_ip'),
            'updated_by' => Yii::t('common', 'updated_by'),
            'updated_at' => Yii::t('common', 'updated_at'),
            'updated_from' => Yii::t('common', 'updated_from'),
            'updated_ip' => Yii::t('common', 'updated_ip'),
            'is_deleted' => Yii::t('common', 'is_deleted'),
        ];
    }

    /**
     * 获取展馆名称
     * @param $id
     * @return null|string
     */
    public static function getHallName($id){
        $model = ExhibitionHall::findOne($id);
        return $model ? $model->title : null;
    }
}
